﻿using System.ComponentModel.DataAnnotations;

namespace ModalValidation
{
    public class Employee_EnsureSalary:ValidationAttribute
    {
        protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
        {
            var employee = validationContext.ObjectInstance as Employee;

            if (employee != null && !string.IsNullOrWhiteSpace(employee.Position) && employee.Position.Equals("Manager", StringComparison.OrdinalIgnoreCase))
            {
                if (employee.Salary < 100000)
                {
                    return new ValidationResult("Salary for Manager should be at least 100000");
                }                
            }
            return ValidationResult.Success;
        }

    }
}
